<?php
namespace App\Http\Controllers\ApiUser;

use App\Service\Member\OrderService;
use Illuminate\Http\Request;

class OrderController extends BaseController
{
    //订单

    public function __construct(OrderService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getList(Request $request)
    {
        $token = $request->post('token', '');
        $pages['start'] = $request->post('page', 1);
        $pages['limit'] = $request->post('size', 10);
        $pas['type'] = $request->post('type', 0); //2小区医护，3陪诊
        $pas['status'] = $request->post('status', 0); //0所有，1待服务，2已完成，3已取消
        $pas['uid'] = $this->db->uidByToken($token);
        if (!$pas['uid']) {
            return $this->toJson(-2, '没有登录');
        }
        if (!in_array($pas['type'], [2, 3])) {
            return $this->toJson(-2, '订单类型错误');
        }
        if ($pas['type'] == 2) {
            $res = $this->db->yihuList($pages, $pas);
        } else {
            $res = $this->db->peizhenList($pages, $pas);
        }
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //医护详情
    public function yihuOne(Request $request)
    {
        $token = $request->post('token', '');
        $id = $request->post('yw_id', 0); //业务ID
        $uid = $this->db->uidByToken($token);
        if (!$uid) {
            return $this->toJson(-2, '没有登录');
        }
        $res = $this->db->yihuOne($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //陪诊详情
    public function peizhenOne(Request $request)
    {
        $token = $request->post('token', '');
        $id = $request->post('yw_id', 0); //业务ID
        $uid = $this->db->uidByToken($token);
        if (!$uid) {
            return $this->toJson(-2, '没有登录');
        }
        $res = $this->db->peizhenOne($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }
}